package com.qyy.remotemonitor.common.ui;

import android.os.Bundle;

import com.blankj.utilcode.util.LogUtils;
import com.qyy.remotemonitor.MyApplication;
import com.qyy.remotemonitor.common.di.DaggerFragmentCommonComponent;
import com.qyy.remotemonitor.common.di.FragmentCommonComponent;
import com.qyy.remotemonitor.common.di.interfaces.DiFragmentSupport;
import com.wang.android.library.di.EasyBasePresenter;
import com.wang.android.library.di.modules.FragmentModule;
import com.wang.android.library.ui.FBaseDaggerFragment;

import javax.inject.Inject;

/**
 * Created by WangHuanyu on 2018/1/29.
 */

public abstract class BaseFragment<P extends EasyBasePresenter> extends FBaseDaggerFragment
        implements DiFragmentSupport
{
    @Inject
    protected P presenter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        initInject();
        if(presenter != null){
            presenter.attachView(this);
            presenter.setContext(getContext());
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(presenter != null){
            presenter.detachView();
        }
    }

    @Override
    public void onResume()
    {
        super.onResume();
        LogUtils.d("=================this is " + this.getClass().getSimpleName() + "=================");
    }

    @Override
    public abstract void initInject();

    @Override
    public FragmentModule getFragmentModule() {
        return new FragmentModule(this);
    }

    @Override
    public FragmentCommonComponent getFragmentComponent() {
        return DaggerFragmentCommonComponent.builder()
                .appCommonComponent(((MyApplication) getActivity().getApplication()).getAppCommonComponent())
                .fragmentModule(getFragmentModule())
                .build();
    }
}
